package cn.com.digitalnet.ad.util;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * Mybatis工具类，用于使用sqlsession的api
 * @author qidafang
 */
@Component
public class MybatisUtil {
	
	/**
	 * 注入mybatis的sessionfactory
	 */
	@Autowired
	private SqlSessionFactory sqlSessionFactory;
	
	/**
	 * 获得sqlsession
	 * @return
	 */
	public SqlSession getSqlSession(){
		return SqlSessionUtils.getSqlSession(sqlSessionFactory);
	}
	
	/**
	 * 清空sqlsession的缓存
	 */
	public void clearSqlSessionCache(){
		getSqlSession().clearCache();
	}
	
}
